package com.bxshey.happyTown.controller;

import com.bxshey.happyTown.dto.login.InsertDTO;
import com.bxshey.happyTown.dto.login.LoginDTO;
import com.bxshey.happyTown.result.Result;
import com.bxshey.happyTown.service.LoginService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @作者：不想说话而已
 * @Date：2024/1/4 0:18
 */

@RestController
public class LoginController {

    @Resource
    LoginService loginService;

    /**
     * 登录
     * @param user 登录信息
     * @return 用户信息，令牌
     */
    @PostMapping("/login")
    public Result<?> login(@RequestBody LoginDTO user){
        return Result.success(loginService.login(user));
    }

    /**
     * 注册
     *
     * @param user 注册信息
     * @return 新增用户id
     */
    @PostMapping("/enroll")
    public Result<?> insert(@RequestBody InsertDTO user) {
        return Result.success("注册成功",loginService.enroll(user));
    }

}
